VERSION 5.00
Begin VB.Form frmDepartment 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "DEPARTMENT"
   ClientHeight    =   3960
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10080
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3960
   ScaleWidth      =   10080
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame frmFooter 
      Height          =   855
      Left            =   120
      TabIndex        =   8
      Top             =   2880
      Width           =   9735
      Begin VB.CommandButton btnCancel 
         Caption         =   "CANCEL [F12]"
         Height          =   495
         Left            =   8280
         TabIndex        =   2
         Top             =   240
         Width           =   1215
      End
      Begin VB.CommandButton btnUpdate 
         Caption         =   "UPDATE [F11]"
         Height          =   495
         Left            =   6960
         TabIndex        =   1
         Top             =   240
         Width           =   1215
      End
      Begin VB.CommandButton btnDelete 
         Caption         =   "DELETE [F10]"
         Height          =   495
         Left            =   5640
         TabIndex        =   0
         Top             =   240
         Width           =   1215
      End
   End
   Begin VB.Frame frmDetail 
      Height          =   1815
      Left            =   120
      TabIndex        =   7
      Top             =   1080
      Width           =   9735
      Begin VB.TextBox txtLocation 
         Height          =   375
         Left            =   1440
         TabIndex        =   5
         Top             =   1200
         Width           =   6255
      End
      Begin VB.TextBox txtDeptHead 
         Height          =   375
         Left            =   1440
         TabIndex        =   4
         Top             =   720
         Width           =   6255
      End
      Begin VB.TextBox txtDeptName 
         Height          =   375
         Left            =   1440
         TabIndex        =   3
         Top             =   240
         Width           =   6255
      End
      Begin VB.Label lblLocation 
         Caption         =   "LOCATION"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label lblDeptHead 
         Caption         =   "DEPT HEAD"
         Height          =   255
         Left            =   240
         TabIndex        =   14
         Top             =   840
         Width           =   1095
      End
      Begin VB.Label lblDeptName 
         Caption         =   "DEPT NAME"
         Height          =   255
         Left            =   240
         TabIndex        =   13
         Top             =   360
         Width           =   1215
      End
   End
   Begin VB.Frame frmHeader 
      Height          =   975
      Left            =   120
      TabIndex        =   6
      Top             =   120
      Width           =   9735
      Begin VB.Frame frmInfo 
         Height          =   735
         Left            =   4680
         TabIndex        =   16
         Top             =   120
         Width           =   2415
         Begin VB.Label lblInfo 
            Alignment       =   2  'Center
            BackColor       =   &H00FF0000&
            Caption         =   "New"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H0000FFFF&
            Height          =   375
            Left            =   120
            TabIndex        =   17
            Top             =   240
            Width           =   2175
         End
      End
      Begin VB.CommandButton btnStartInput 
         Caption         =   "START INPUT"
         Height          =   615
         Left            =   7920
         TabIndex        =   10
         Top             =   240
         Width           =   1575
      End
      Begin VB.CommandButton btnSearchDept 
         Caption         =   "---"
         Height          =   375
         Left            =   2520
         TabIndex        =   12
         TabStop         =   0   'False
         Top             =   360
         Width           =   495
      End
      Begin VB.TextBox txtDeptNo 
         Alignment       =   1  'Right Justify
         Height          =   375
         Left            =   1440
         MaxLength       =   9
         TabIndex        =   9
         Text            =   "123456789"
         Top             =   360
         Width           =   975
      End
      Begin VB.Label lblDepartmentNo 
         Caption         =   "DEPT NO"
         Height          =   255
         Left            =   240
         TabIndex        =   11
         Top             =   360
         Width           =   1095
      End
   End
End
Attribute VB_Name = "frmDepartment"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private nIsNewCode As Boolean
Private nIsInput As Boolean

'---------------------------------------------------------------------------------------
' Procedure : btnCancel_Click
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub btnCancel_Click()
    If MsgBox("Cancel input?", vbYesNo, "Question") = vbYes Then
        nIsInput = False
        InputAreaChange (True)
        SetLabelInfo
        Me.txtDeptNo.SetFocus
    Else
        Me.txtDeptName.SetFocus
    End If
End Sub

'---------------------------------------------------------------------------------------
' Procedure : btnSearchDept_Click
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub btnSearchDept_Click()
    Dim frmSrchDept As New frmSearchDept
    frmSrchDept.Show vbModal
    Me.txtDeptNo.SetFocus
End Sub

'---------------------------------------------------------------------------------------
' Procedure : btnStartInput_Click
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub btnStartInput_Click()
    nIsInput = True
    InputAreaChange (False)
    SetLabelInfo
    Me.txtDeptName.SetFocus
End Sub

'---------------------------------------------------------------------------------------
' Procedure : btnUpdate_Click
' Author    : PQ Tri
' Date      : 27/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub btnUpdate_Click()
    nIsNewCode = False
    nIsInput = False
    MsgBox "Sucessfully Updated!", vbInformation, "Info"
    InputAreaChange (True)
    SetLabelInfo
    Me.txtDeptNo.SetFocus
End Sub

'---------------------------------------------------------------------------------------
' Procedure : Form_Load
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub Form_Load()
    SetInit
    InputAreaChange (True)
    Me.txtDeptNo.SelLength = 9
End Sub

'---------------------------------------------------------------------------------------
' Procedure : SetInit
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Sub SetInit()
    Me.txtDeptNo.Text = 0
    Me.txtDeptHead.Text = vbNullString
    Me.txtDeptName.Text = vbNullString
    Me.txtLocation.Text = vbNullString
    SetLabelInfo
End Sub

'---------------------------------------------------------------------------------------
' Procedure : SetLabelInfo
' Author    : PQ Tri
' Date      : 27/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub SetLabelInfo()
    If nIsInput Then
        If nIsNewCode Then
            Me.lblInfo.Caption = "INSERTING"
        Else
            Me.lblInfo.Caption = "UPDATING"
        End If
    Else
        If Me.ActiveControl Is Nothing Then
            Me.lblInfo.Caption = "INPUT CODE"
        Else
            If Me.ActiveControl.Name = "btnStartInput" Then
                If nIsNewCode Then
                    Me.lblInfo.Caption = "NEW"
                Else
                    Me.lblInfo.Caption = "UPDATE"
                End If
            Else
                Me.lblInfo.Caption = "INPUT CODE"
            End If
        End If
    End If
End Sub

'---------------------------------------------------------------------------------------
' Procedure : InputAreaChange
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub InputAreaChange(pEnabled As Boolean)
    ''HEADER
    Me.lblDepartmentNo.Enabled = pEnabled
    Me.txtDeptNo.Enabled = pEnabled
    Me.btnStartInput.Enabled = pEnabled
    Me.btnSearchDept.Enabled = pEnabled
    
    ''DETAIL
    Me.txtDeptName.Enabled = Not pEnabled
    Me.lblDeptName.Enabled = Not pEnabled
    Me.txtDeptHead.Enabled = Not pEnabled
    Me.lblDeptHead.Enabled = Not pEnabled
    Me.txtLocation.Enabled = Not pEnabled
    Me.lblLocation.Enabled = Not pEnabled
    
    ''FOOTER
    Me.btnDelete.Enabled = Not pEnabled
    Me.btnUpdate.Enabled = Not pEnabled
    Me.btnCancel.Enabled = Not pEnabled
End Sub

Private Sub txtDeptNo_LostFocus()
    SetLabelInfo
End Sub

'---------------------------------------------------------------------------------------
' Procedure : txtDeptNo_Validate
' Author    : PQ Tri
' Date      : 26/11/2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub txtDeptNo_Validate(Cancel As Boolean)
    On Error GoTo Err_DeptNo
    
    If Me.txtDeptNo.Text = 0 Then
        GoTo Err_DeptNo
    End If
    
    If Me.txtDeptNo.Text = 1 Then
        ''Dept co ton tai trong database
        Me.txtDeptName.Text = "Information Department"
        Me.txtDeptHead.Text = "Le Hong Linh"
        Me.txtLocation.Text = "Building Waseco, floor 2nd"
        nIsNewCode = False
    Else
        ''Dept khong ton tai trong database
        Me.txtDeptName.Text = ""
        Me.txtDeptHead.Text = ""
        Me.txtLocation.Text = ""
        nIsNewCode = True
    End If
    
    Exit Sub
    
Err_DeptNo:
    If MsgBox("Invalid department!", vbCritical + vbOKOnly, "Info") = vbOK Then
        Me.txtDeptNo.SetFocus
    End If
    Cancel = True

End Sub
